﻿<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:maps="using:Windows.UI.Xaml.Controls.Maps"
    xmlns:mapbinding="using:WpWinNl.Maps"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
    xmlns:Behaviors="using:WpWinNl.Behaviors"
    x:Class="WpWinNl.MapBindingDemo.MainPage"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource MapBindingViewModel}">
  <interactivity:Interaction.Behaviors>
    <Core:EventTriggerBehavior EventName="Loaded">
      <Core:InvokeCommandAction Command="{Binding ShowAreaCommand, Mode=OneWay}" />
    </Core:EventTriggerBehavior>
  </interactivity:Interaction.Behaviors>

  <Page.BottomAppBar>
    <CommandBar>
      <CommandBar.SecondaryCommands>
        <AppBarButton Label="show area" Click="AppBarButton_Click" />
      </CommandBar.SecondaryCommands>
      <AppBarButton Label="Lines" Icon="Italic" Command="{Binding LoadLinesCommand}"/>
      <AppBarButton Label="Polygons" Icon="BrowsePhotos" Command="{Binding LoadPolygonsCommand}" />
      <AppBarButton Label="Points" Icon="MapPin" Command="{Binding LoadIconsCommand}" />
      <AppBarButton Label="Delete all" Icon="Delete" Command="{Binding DeleteAllCommand}" />
    </CommandBar>
  </Page.BottomAppBar>


	<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
		<interactivity:Interaction.Behaviors>
			<Behaviors:MessageDialogBehavior/>
		</interactivity:Interaction.Behaviors>
		<Grid Margin="12,0,12,0" >
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="*"/>
			</Grid.RowDefinitions>
			<StackPanel Margin="0,18,0,5">
				<TextBlock TextWrapping="Wrap" Text="Drawing shapes" FontSize="26.667"/>
			</StackPanel>
			<maps:MapControl x:Name="MyMap" Grid.Row="1"
				mapbinding:MapBindingHelpers.MapViewArea="{Binding Area, Mode=TwoWay}">
				<interactivity:Interaction.Behaviors>
					<mapbinding:MapShapeDrawBehavior LayerName="Points" ItemsSource="{Binding Icons}" PathPropertyName="Points">
						<mapbinding:MapShapeDrawBehavior.EventToCommandMappers>
              <mapbinding:EventToCommandMapper EventName="MapTapped" CommandName="SelectCommand"/>
						</mapbinding:MapShapeDrawBehavior.EventToCommandMappers>
						<mapbinding:MapShapeDrawBehavior.ShapeDrawer>
							<mapbinding:MapIconDrawer  ImageUri="ms-appx:///Assets/wplogo.png"/>
						</mapbinding:MapShapeDrawBehavior.ShapeDrawer>
					</mapbinding:MapShapeDrawBehavior>

					<mapbinding:MapShapeDrawBehavior LayerName="Lines" ItemsSource="{Binding Lines}" PathPropertyName="Points">
						<mapbinding:MapShapeDrawBehavior.EventToCommandMappers>
              <mapbinding:EventToCommandMapper EventName="MapTapped" CommandName="SelectCommand"/>
						</mapbinding:MapShapeDrawBehavior.EventToCommandMappers>
						<mapbinding:MapShapeDrawBehavior.ShapeDrawer>
              <mapbinding:MapPolylineDrawer Color="BlueViolet"/>
            </mapbinding:MapShapeDrawBehavior.ShapeDrawer>
					</mapbinding:MapShapeDrawBehavior>

					<mapbinding:MapShapeDrawBehavior LayerName="Shapes" ItemsSource="{Binding Polygons}" PathPropertyName="Points">
						<mapbinding:MapShapeDrawBehavior.EventToCommandMappers>
              <mapbinding:EventToCommandMapper EventName="MapTapped" CommandName="SelectCommand"/>
						</mapbinding:MapShapeDrawBehavior.EventToCommandMappers>
						<mapbinding:MapShapeDrawBehavior.ShapeDrawer>
							<mapbinding:MapPolygonDrawer Color="Green" Width="10"/>
						</mapbinding:MapShapeDrawBehavior.ShapeDrawer>
					</mapbinding:MapShapeDrawBehavior>

				</interactivity:Interaction.Behaviors>
			</maps:MapControl>
		</Grid>

	</Grid>
</Page>
